package com.livsdesign.tools.condition

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel


class ConditionViewModel : ViewModel() {

    private val conditionCountLiveData = MutableLiveData<Int>()
    private val conditionTasks = mutableListOf<ConditionTask>()

    val countLiveData: LiveData<Int> = conditionCountLiveData

    fun addConditionTask(vararg tasks: ConditionTask) {
        //当conditionTask增加时UI也要注册监听
        tasks.forEach {
            conditionTasks.add(it)
//            if(it.template.mState.hasObservers()){
//                it.template.mState.observe()
//            }
        }
        conditionCountLiveData.postValue(conditionTasks.size)
    }

    fun getTargets(): List<ConditionTask> {
        return conditionTasks
    }


}